<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head th:replace="dashboard/header :: header"></head>
<body class="gray-bg">

<!--
@desc 方法 管理
@author WeiXiaoJin
@since 2020-01-26 09:30:11
-->

	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="operlog-form">
					<div class="select-list">
						<ul>
							<li><label> 方法名称</label><input type="text" name="condition[method|like]"/></li>
						<li>
							<a class="btn btn-success btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</li>
						</ul>
					</div>
				</form>
			</div>

			<div class="btn-group-sm" id="toolbar" role="group">
		        <!--
				<a class="btn btn-success" onclick="$.operate.add()">
	                <i class="fa fa-plus"></i> 新增
	            </a>
	            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()">
		            <i class="fa fa-edit"></i> 修改
		        </a>
		        <a class="btn btn-danger" onclick="$.operate.clean()">
	                <i class="fa fa-trash"></i> 清空
	            </a>
	            -->
				<a class="btn btn-danger btn-del disabled" onclick="$.operate.removeAll()">
		            <i class="far fa-trash-alt"></i> 删除
		        </a>
	            <a class="btn btn-warning" onclick="$.table.exportExcel()">
		            <i class="fa fa-download"></i> 导出
		        </a>
				<a class="btn btn-danger" onclick="operateAdd()">
	                <i class="fa fa-plus"></i> 新增规则
	            </a>
	        </div>

			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>

	<footer th:replace="dashboard/footer :: footer"></footer>

	<script>
		var prefix = ctx + "base/logger/logMethodRuntime/" ;

		$(function() {
		    var options = {
		        url: prefix +"datatables" ,
		        createUrl: prefix + 'add' ,
		        updateUrl: prefix +"modify?id={id}" ,
		        statusUrl: prefix +"changeStatus?id={id}" ,
		        cleanUrl: prefix + "clean",
		        detailUrl: prefix +"detail?id={id}",
		        removeUrl: prefix + "delete" ,
		        exportUrl: prefix + "exportExcel",
		        sortName: "operTime",
		        uniqueId:"id" ,
		        sortOrder: "desc",
                modalName: "方法",
                pageSize: 25,
		        escape: true,
		        showPageGo: true,
		        rememberSelected: true,
		        columns: [{field: 'state',checkbox: true },

					{field: 'applicationName', title: '应用名称'},
					{field: 'method', title: '方法' , formatter:function(v , r , i){
							if(v == null){
								return null ; 
							}	
							if(r.type != null){
								var t = r.type + "->" + v ;
								return t ; 
							}
						}
					},
					{field: 'count', title: '总数', align: 'center'},
					{field: 'ok', title: '成功', align: 'center'},
					{field: 'fail', title: '失败', align: 'center'},
					{field: 'rps', title: '每分钟', align: 'center'},
					{field: 'avg', title: '平均(ms)', align: 'center'},
					{field: 'min', title: '最小(ms)', align: 'center'},
					{field: 'max', title: '最大(ms)', align: 'center'},
			        {field: 'id' , title: '操作', align: 'center', width:'150px', formatter: function(value, row, index) {
			                var actions = [];

			                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-edit"></i>详情</a> ');
			                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="addTriger(\'' + row.id + '\')"><i class="fa fa-edit"></i>预警</a> ');

			                return actions.join('');
			          }
			     }]
		    };
		    $.table.init(options);
		});
	
		// 添加预警规则
		function operateAdd(){
			var url = ctx + "base/logger/logTrigger/add?alarmEventType=ALARM_METHOD_RUNTIME&ruleType=method_runtime_rule" ; 
			$.modal.open("添加方法运行预警机制." , url) ; 	
		}

	</script>
</body>
</html>

